<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>注册入口</span>
      </div>
    </template>

    <el-form
        label-width="100px"
        label-position="left"
        size="small"
        inline="inline"
        :rules="rules"
        ref="loginForm"
        v-model="loginForm"
    >
      <el-row justify="center">
        <el-form-item label="账户" prop="userName">
          <el-input v-model="loginForm.userName"/>
        </el-form-item>
      </el-row>

      <el-row justify="center">
        <el-form-item label="密码" prop="password">
          <el-input v-model="loginForm.password"/>
        </el-form-item>
      </el-row>

      <el-row justify="center">
        <el-form-item label="确认密码" prop="passwordAgain">
          <el-input v-model="loginForm.passwordAgain"/>
        </el-form-item>
      </el-row>

      <el-row justify="center">
        <el-form-item label="手机号">
          <el-input/>
        </el-form-item>
      </el-row>

      <el-row justify="space-evenly">
        <el-col :span="6" style="margin-left: 12px">
          <el-form-item label="验证码"></el-form-item>
        </el-col>
        <el-col :span="6">
          <el-input/>
        </el-col>
        <el-col :span="6">
          <el-button class="but">获取验证码</el-button>
        </el-col>

      </el-row>

      <el-row justify="center">
        <el-button class="but" @click="register">注册</el-button>
        <el-button class="but">取消</el-button>
      </el-row>

    </el-form>
  </el-card>
</template>

<script>


export default {
  name: "login-register",
  data() {
    return {
      loginForm: {
        userName:'',
        password:'',
        passwordAgain:''
      },
      rules: {
        userName:[{required:true,message:"用户名不能为空",trigger:'blur'}],
        password:[{required:true,message:"密码不能为空",trigger:'blur'}],
        passwordAgain:[{required:true,message:"请再次输入密码",trigger:'blur'}]
      }
    }
  },
  methods: {
    register: function () {
      this.$refs.loginForm.validate((valid) => {
        if (!valid) {
          this.$message.error('请填写全部注册信息')
        } else {

          if(this.loginForm.passwordAgain!==this.loginForm.password) {
            this.$message.error('两次请输入相同的密码')
          } else {
            this.axios
                .post()
          }
        }
      })

    }
  }
}
</script>

<style scoped>

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.box-card {
  width: 400px;
  margin-left: 60%;
  margin-top: 14%;
  border-radius: 22px;

}
.but{
  background-color: #4C8ADA;
  color: white;
}
</style>